﻿namespace HySoft.Cash.DB
{
    using Huayou.Common.Database;
    using Huayou.Utils;
    using HySoft.Cash.BaseClass;
    using HySoft.Cash.Structure;
    using System;
    using System.Data;

    public class TinvoicelistDB : BaseDB
    {
        public TinvoicelistDB(DBOperate oper) : base(oper)
        {
        }

        public bool Add(TinvoicelistDT detail)
        {
            int num = 0;
            string strSql = string.Concat(new object[] { "INSERT INTO tInvoiceList (OrgSid,InvoiceDate,InvoiceAmount,IsValid,ReceiveAmount,Note) VALUES (", detail.OrgSid, ",'", StringUtils.ToSQL(detail.InvoiceDate), "','", StringUtils.ToSQL(detail.InvoiceAmount), "',", detail.IsValid, ",'", StringUtils.ToSQL(detail.ReceiveAmount), "','", StringUtils.ToSQL(detail.Note), "')" });
            try
            {
                try
                {
                    num = base.ExecuteForInt(strSql);
                }
                catch (Exception exception)
                {
                    throw exception;
                }
            }
            finally
            {
            }
            return (num == 1);
        }

        public bool Delete(int Sid)
        {
            int num = 0;
            string strSql = "DELETE FROM tInvoiceList where (Sid=" + Sid + ")";
            try
            {
                try
                {
                    num = base.ExecuteForInt(strSql);
                }
                catch (Exception exception)
                {
                    throw exception;
                }
            }
            finally
            {
            }
            return (num == 1);
        }

        public bool Edit(TinvoicelistDT detail)
        {
            int num = 0;
            string strSql = string.Concat(new object[] { "UPDATE tInvoiceList set OrgSid=", detail.OrgSid, ",InvoiceDate='", StringUtils.ToSQL(detail.InvoiceDate), "',InvoiceAmount='", StringUtils.ToSQL(detail.InvoiceAmount), "',IsValid=", detail.IsValid, ",ReceiveAmount='", StringUtils.ToSQL(detail.ReceiveAmount), "',Note='", StringUtils.ToSQL(detail.Note), "' where (Sid=", detail.Sid, ")" });
            try
            {
                try
                {
                    num = base.ExecuteForInt(strSql);
                }
                catch (Exception exception)
                {
                    throw exception;
                }
            }
            finally
            {
            }
            return (num == 1);
        }

        public TinvoicelistDT Get(int Sid)
        {
            TinvoicelistDT tdt = new TinvoicelistDT();
            try
            {
                try
                {
                    string strSql = "select * from tInvoiceList where (Sid=" + Sid + ")";
                    DataTable table = base.ExecuteForDataTable(strSql);
                    DataRow row = null;
                    if (table.Rows.Count >= 0)
                    {
                        row = table.Rows[0];
                        tdt.Sid = Convert.ToInt32(row["Sid"]);
                        tdt.OrgSid = Convert.ToInt32(row["OrgSid"]);
                        tdt.InvoiceDate = Convert.ToString(row["InvoiceDate"]);
                        tdt.InvoiceAmount = Convert.ToString(row["InvoiceAmount"]);
                        tdt.IsValid = Convert.ToInt32(row["IsValid"]);
                        tdt.ReceiveAmount = Convert.ToString(row["ReceiveAmount"]);
                        tdt.Note = Convert.ToString(row["Note"]);
                        tdt.Penalty = Convert.ToString(row["Penalty"]);
                        tdt.InterestCharges = Convert.ToString(row["InterestCharges"]);
                        tdt.PaymentDate = Convert.ToString(row["PaymentDate"]);
                        tdt.Guid = Convert.ToString(row["Guid"]);
                    }
                }
                catch (Exception exception)
                {
                    throw exception;
                }
            }
            finally
            {
            }
            return tdt;
        }

        public DataTable GetList()
        {
            DataTable table = null;
            try
            {
                try
                {
                    string strSql = "select * from tInvoiceList";
                    table = base.ExecuteForDataTable(strSql);
                }
                catch (Exception exception)
                {
                    throw exception;
                }
            }
            finally
            {
            }
            return table;
        }
    }
}

